﻿using Domain.Models;
using Domain.Models.Identity;
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using System.Reflection;

namespace Domain.Context
{
    public partial class ApplicationDBContext : IdentityDbContext<Account, Role, Guid, UserClaim, UserRole, UserLogin, RoleClaim, UserToken>
    {
        protected IConfiguration Configuration;
        
        public ApplicationDBContext(IConfiguration configuration)
        {
            this.Configuration = configuration;
        }

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            base.OnConfiguring(optionsBuilder);
        }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            base.OnModelCreating(modelBuilder);
            var configurationNamespace = "Domain.Configurations";
            modelBuilder.ApplyConfigurationsFromAssembly(Assembly.GetExecutingAssembly(),
                type => type.Namespace == configurationNamespace);

            modelBuilder.Entity<Role>().ToTable("Role");
            modelBuilder.Entity<UserLogin>().ToTable("UserLogin");
            modelBuilder.Entity<RoleClaim>().ToTable("RoleClaim");
            modelBuilder.Entity<UserToken>().ToTable("UserToken");
            modelBuilder.Entity<UserClaim>().ToTable("UserClaim");
            modelBuilder.Entity<UserRole>().ToTable("UserRole");
        }
    }
}
